
function GetCameraState(a)
{
	flashpoint();

//	printf('# RWO 9/16 minimal testing on this script ,seems to work OK');
	printf('# for most parameter tags');
	printf('# can run GetCameraState(param,...)');
	printf('# select from the listings (a-z)');
	printf('# select the parameter tag ');
	printf('# returns the current state');
	printf('# for some parameter tags, GetProductInfo() is used ');
	printf('# GPI[0] means a GetProductInfo() call');
	
	var alphaNum = new Array();		// associate a number with each alpha character

	var usetVar=new Array("uset0","uset1","uset2","uset3","uset4","uset5","uset6","uset7" );
	var isetVar=new Array("iset0","iset1","iset2","iset3","iset4","iset5","iset6","iset7" );
	var ssetVar=new Array("sset0","sset1","sset2","sset3","sset4","sset5","sset6","sset7" );
	
	var setTitle=new Array("title0","title1","title2","title3","title4","title5","title6","title7" );

	var i,setting,achar,count;
	
	writeMenu('"GetCameraState"','"EXTRA"','"GCStateOption"');
	writeVariables();
	printf('declare s: readwrite ');
	printf('declare s: theCompType ');

	print('declare u: uset0');
	for(i=1 ;i< usetVar.length ; i++) print(",",usetVar[i]); printf(' ');
	print('declare i: iset0');
	for(i=1 ;i< isetVar.length ; i++) print(",",isetVar[i]); printf(' ');
	print('declare s: sset0');
	for(i=1 ;i< ssetVar.length ; i++) print(",",ssetVar[i]); printf(' ');

	print('declare s: title0');	
	for(i=1 ;i< setTitle.length ; i++) print(",",setTitle[i]); printf(' ');

	printf('declare u: doit,countSetting');
	
	printf('<br>','#**** OPEN FILE ****');
  	printf('outFile="/System/ZGState.txt"');
	writeFileOpen();


	/*
	 * MENU 1 
	 * for each alphabetic character(a,b,c....z) write a SetOption
	 * but only for one that's used
	 * user selects first character of parameter tag (i.e. a for acpd )
	 */
	 
	achar=" ";		// start with a blank
	count=1;
	printf('LOOP:');
	printf('DisplayClear()');
	for( i=1; i<a.length ; i++)
	if( a[i].param.substring(1,2) != achar  ){
			achar=a[i].param.substring(1,2);					// save the first character
			alphaNum[ a[i].param.substring(1,2) ] = count;		// and count associated with this char
			printf('SetOption(',count,',"',achar , '",0)' );	// do the SetOption stuff
			count++;	
	} 
	printf('GetOption(choice)');
	

	/*
	 * MENU 2
	 * place all tags starting with 'a' together in one option list
	 * do the same for 'b', 'c', etc,..
	 * example "deft", "dfmt", "drdn" will all be in the same menu list
	 */	 

	achar=" ";		// start with a blank
	count=0;	
	
	for( i=1; i<a.length ; i++){
	
//	if( a[i].host == "Read") continue;

	if( a[i].param.substring(1,2) != achar )
	{
			// finished off previous option list
			if( i!=1){
					printf('GetOption(choice2)');	
					printf('end<br>');
			}

 			count++;			
			printf('if choice == ',alphaNum[ a[i].param.substring(1,2) ] );		// get count value
			printf('SetOption(500,"Quit",1)');
											
			achar=a[i].param.substring(1,2);												
	}	
				
		printf('SetOption(',i,",",a[i].param,',0)' );
	}// end of for loop 

	// the last one has to have this, a hack, sorry.......
	printf('GetOption(choice2)');	
	printf('end');


/* MENU 3 (lowest layer)
 * This one has ONE parameter tag per if .. end set
 */
 
  	/* 
  	 * Generate a series of
  	 *  if <   >
  	    param = "abcd"
  	    end
  	 * Each if ... end set represents a single parameter tag and its possible values
	 * type should be either Enum, UInt, String or Fixed ...
	 */

	printf(' ');
	printf('theType="UInt"');
	printf('theCompType = " "');
	
 	for(i=1 ; i<a.length ; i++){		
 		printf('<br>if choice2 == ',i  );
		printf('param = ',a[i].param );

		//  EnumListHex type
		if( a[i].type == "Enum List Hex" || a[i].type == "Hex")  printf('theType="Hex"');
		// an Fixed or BitMask type
 		if( (a[i].type=="Fixed") || (a[i].type=="BitMask")) printf('theType="Hex"');
		if( a[i].type=="SInt" )	printf('theType="SInt"');
		if( a[i].type=="String" )	printf('theType="String"');
		if( a[i].fposComm=="GetProductInfo" ) printf('theCompType = "GetProductInfo"');	
		printf('end');

 	}// end of for loop
 
 	printf('uvar=0');
 	printf('ivar=0');
 	printf('bvar=0');
 	printf('svar=""');
 	printf(' ');
 	
 	printf('if theCompType == "GetProductInfo"')
 	printf('goto GETPRODUCTINFO ')
 	printf('end')
 	printf(' ');
 	
 	printf( 'if theType == "Hex" ' );
 	printf('status=GetCameraState(param,uvar)');
 	printf('bvar = uvar ');
 	printf('DisplayLine(param,"[",status,"] ",bvar )' );
 	printf('Wait(2000)');
 	printf('end');
 	printf(' ');
 	
 	printf( 'if theType == "String" ' );
 	printf('status=GetCameraState(param,svar)');
 	printf('DisplayLine(param,"[",status,"] ",svar )' );
 	printf('Wait(2000)');
 	printf('end ');
 
 	printf( 'if theType == "UInt" ' );
 	printf('status=GetCameraState(param,uvar)');
 	printf('DisplayLine(param,"[",status,"] ",uvar )' );
 	printf('Wait(2000)');
 	printf('end ');
 	
 	printf( 'if theType == "SInt" ' );
 	printf('status=GetCameraState(param,ivar)');
 	printf('DisplayLine(param,"[",status,"] ",ivar )' );
 	printf('Wait(2000)');
 	printf('end ');
 	
	printf('goto CONTINUE');
	printf(' ');
	printf('GETPRODUCTINFO:')
 	printf( 'if theType == "Hex" ' );
 	printf('status=GetProductInfo(param,uvar)');
 	printf('bvar = uvar ');
 	printf('DisplayLine(param," GPI[",status,"] ",bvar )' );
 	printf('Wait(2000)');
 	printf('end');
 	printf(' ');
 	
 	printf( 'if theType == "String" ' );
 	printf('status=GetProductInfo(param,svar)');
 	printf('DisplayLine(param," GPI[",status,"] ",svar )' );
 	printf('Wait(2000)');
 	printf('end ');
 
 	printf( 'if theType == "UInt" ' );
 	printf('status=GetProductInfo(param,uvar)');
 	printf('DisplayLine(param," GPI[",status,"] ",uvar )' );
 	printf('Wait(2000)');
 	printf('end ');
 	
 	printf( 'if theType == "SInt" ' );
 	printf('status=GetProductInfo(param,ivar)');
 	printf('DisplayLine(param," GPI[",status,"] ",ivar )' );
 	printf('Wait(2000)');
 	printf('end ');
 	
 	printf('CONTINUE:')
	printf('if choice2 != 500');
	printf('goto LOOP');
	printf('end');
	
	writeFileClose();
	printf('exitscript');

}

